From c0efb8dc852805fd4d3c2691aca1f6c52f6b6ac7 Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Fri, 11 Nov 2005 18:01:44 +0100 Subject: [PATCH] Rename the commands inside the hotplug scripts to match those used by hotplug and udev. Pass all commands through from xen-backend.agent or xen-backend.rules rather than second-guessing the individual scripts. This should make it easier to tear down devices cleanly, especially the dangling vifs we are seeing at the moment. Cope with a missing type node inside the block script, as we don't want to resurrect a removed node by writing a hotplug error message. Log failure of iptables command. Signed-off-by: Ewan Mellor --- tools/examples/block | 29 ++++++++++++++--------------- tools/examples/block-common.sh | 7 +++++-- tools/examples/vif-bridge | 9 +++++---- tools/examples/vif-common.sh | 13 +++++++++++-- tools/examples/vif-nat | 6 +++--- tools/examples/vif-route | 6 +++--- tools/examples/xen-backend.agent | 32 +++++++++++--------------------- tools/examples/xen-backend.rules | 7 ++++--- 8 files changed, 56 insertions(+), 53 deletions(-) diff --git a/tools/examples/block b/tools/examples/block index c5b6b6c215..79636ac20a 100644 --- a/tools/examples/block +++ b/tools/examples/block @@ -3,6 +3,12 @@ dir=$(dirname "$0") . "$dir/block-common.sh" +case "$command" in + online | offline) + exit 0 + ;; +esac + expand_dev() { local dev case $1 in @@ -16,10 +22,10 @@ expand_dev() { echo -n $dev } -t=$(xenstore_read "$XENBUS_PATH"/type || true) +t=$(xenstore_read_default "$XENBUS_PATH"/type "MISSING") case "$command" in - bind) + add) p=$(xenstore_read "$XENBUS_PATH"/params) case $t in phy) @@ -38,32 +44,25 @@ case "$command" in done exit 1 ;; - - *) - [ -x /etc/xen/scripts/block-"$t" ] && \ - /etc/xen/scripts/block-"$t" bind $p - ;; esac ;; - unbind) - node=$(xenstore_read "$XENBUS_PATH"/node) + remove) case $t in phy) exit 0 ;; file) + node=$(xenstore_read "$XENBUS_PATH"/node) losetup -d $node exit 0 ;; - - *) - [ -x /etc/xen/scripts/block-"$t" ] && \ - /etc/xen/scripts/block-"$t" unbind $node - ;; - esac ;; esac + +# If we've reached here, $t is neither phy nor file, so fire a helper script. +[ -x /etc/xen/scripts/block-"$t" ] && \ + /etc/xen/scripts/block-"$t" "$command" $node diff --git a/tools/examples/block-common.sh b/tools/examples/block-common.sh index 397f588c71..2e46831111 100644 --- a/tools/examples/block-common.sh +++ b/tools/examples/block-common.sh @@ -19,9 +19,12 @@ dir=$(dirname "$0") . "$dir/xen-hotplug-common.sh" -command="$1" +findCommand "$@" -if [ "$command" != "bind" ] && [ "$command" != "unbind" ] +if [ "$command" != "online" ] && + [ "$command" != "offline" ] && + [ "$command" != "add" ] && + [ "$command" != "remove" ] then log err "Invalid command: $command" exit 1 diff --git a/tools/examples/vif-bridge b/tools/examples/vif-bridge index d95d8ecef5..c4bac8244c 100755 --- a/tools/examples/vif-bridge +++ b/tools/examples/vif-bridge @@ -9,7 +9,7 @@ # places, then this script is the default. # # Usage: -# vif-bridge (up|down) +# vif-bridge (add|remove|online|offline) # # Environment vars: # vif vif interface name (required). @@ -47,7 +47,7 @@ then fi case "$command" in - up) + online) if brctl show "$bridge" | grep "$vif" >&/dev/null then log debug "$vif already attached to $bridge" @@ -58,9 +58,9 @@ case "$command" in fatal "brctl addif $bridge $vif failed" ifconfig "$vif" up || fatal "ifconfig $vif up failed" - success ;; - down) + + remove) # vifs are auto-removed from bridge. ifconfig "$vif" down || fatal "ifconfig $vif down failed" ;; @@ -69,3 +69,4 @@ esac handle_iptable log debug "Successful vif-bridge operation for $vif, bridge $bridge." +success diff --git a/tools/examples/vif-common.sh b/tools/examples/vif-common.sh index 273cbacab5..c571b8d95b 100644 --- a/tools/examples/vif-common.sh +++ b/tools/examples/vif-common.sh @@ -22,12 +22,21 @@ dir=$(dirname "$0") findCommand "$@" -if [ "$command" != "up" ] && [ "$command" != "down" ] +if [ "$command" != "online" ] && + [ "$command" != "offline" ] && + [ "$command" != "add" ] && + [ "$command" != "remove" ] then log err "Invalid command: $command" exit 1 fi +case "$command" in + add | offline) + exit 0 + ;; +esac + # Parameters may be read from the environment, the command line arguments, and # the store, with overriding in that order. The environment is given by the @@ -46,7 +55,7 @@ vif="${vif:?}" function frob_iptable() { - if [ "$command" == "up" ] + if [ "$command" == "online" ] then local c="-A" else diff --git a/tools/examples/vif-nat b/tools/examples/vif-nat index 9392f3d0ab..8933285620 100644 --- a/tools/examples/vif-nat +++ b/tools/examples/vif-nat @@ -9,7 +9,7 @@ # places, then vif-bridge is the default. # # Usage: -# vif-nat (up|down) +# vif-nat (add|remove|online|offline) # # Environment vars: # vif vif interface name (required). @@ -40,12 +40,12 @@ netmask=$netmask.$(( $intmask & 0x000000FF )) main_ip=$(ip addr show eth0 | sed -e '/inet /!d;s/^.*inet \([^\s*]\)\s.*$/\1/') case "$command" in - up) + online) ifconfig ${vif} ${vif_ip} netmask ${netmask} up echo 1 >/proc/sys/net/ipv4/conf/${vif}/proxy_arp ipcmd='a' ;; - down) + remove) ifconfig ${vif} down ipcmd='d' ;; diff --git a/tools/examples/vif-route b/tools/examples/vif-route index 7e640b22ff..21bc4b18d7 100755 --- a/tools/examples/vif-route +++ b/tools/examples/vif-route @@ -9,7 +9,7 @@ # places, then vif-bridge is the default. # # Usage: -# vif-route (up|down) +# vif-route (add|remove|online|offline) # # Environment vars: # vif vif interface name (required). @@ -26,12 +26,12 @@ dir=$(dirname "$0") main_ip=$(ip addr show eth0 | sed -e '/inet /!d;s/^.*inet \([^\s*]\)\s.*$/\1/') case "$command" in - up) + online) ifconfig ${vif} ${main_ip} netmask 255.255.255.255 up echo 1 >/proc/sys/net/ipv4/conf/${vif}/proxy_arp ipcmd='a' ;; - down) + remove) ifdown ${vif} ipcmd='d' ;; diff --git a/tools/examples/xen-backend.agent b/tools/examples/xen-backend.agent index 35eb79601a..dddcb3e8e3 100755 --- a/tools/examples/xen-backend.agent +++ b/tools/examples/xen-backend.agent @@ -2,35 +2,25 @@ PATH=/etc/xen/scripts:$PATH +case "$XENBUS_TYPE" in + vbd) + /etc/xen/scripts/block "$ACTION" + ;; + vif) + [ -n "$script" ] && $script "$ACTION" + ;; +esac + case "$ACTION" in add) - case "$XENBUS_TYPE" in - vbd) - /etc/xen/scripts/block bind - ;; - esac ;; remove) - case "$XENBUS_TYPE" in - vbd) - /etc/xen/scripts/block unbind - ;; - vif) - [ -n "$script" ] && $script down - ;; - esac # remove device backend store entries - xenstore-rm -t "$XENBUS_PATH" - xenstore-rm -t "error/$XENBUS_PATH" + xenstore-rm -t "$XENBUS_PATH" || true + xenstore-rm -t "error/$XENBUS_PATH" || true ;; online) - case "$XENBUS_TYPE" in - vif) - [ -n "$script" ] && $script up - ;; - esac ;; offline) ;; esac - diff --git a/tools/examples/xen-backend.rules b/tools/examples/xen-backend.rules index 514768b13c..9c077660d1 100644 --- a/tools/examples/xen-backend.rules +++ b/tools/examples/xen-backend.rules @@ -1,4 +1,5 @@ -SUBSYSTEM=="xen-backend", KERNEL=="vbd*", ACTION=="add", RUN+="/etc/xen/scripts/block bind" -SUBSYSTEM=="xen-backend", KERNEL=="vbd*", ACTION=="remove", RUN+="/etc/xen/scripts/block unbind" -SUBSYSTEM=="xen-backend", KERNEL=="vif*", ACTION=="online", RUN+="$env{script} up" +SUBSYSTEM=="xen-backend", KERNEL=="vbd*", RUN+="/etc/xen/scripts/block $env{ACTION}" +SUBSYSTEM=="xen-backend", KERNEL=="vif*", ACTION=="online", RUN+="$env{script} online" +SUBSYSTEM=="xen-backend", KERNEL=="vif*", ACTION=="offline", RUN+="$env{script} offline" SUBSYSTEM=="xen-backend", ACTION=="remove", RUN+="/usr/bin/xenstore-rm -t $env{XENBUS_PATH}" +SUBSYSTEM=="xen-backend", ACTION=="remove", RUN+="/usr/bin/xenstore-rm -t error/$env{XENBUS_PATH}" -- 2.30.2